package cn.wolfcode.listener;


import cn.wolfcode.core.WebSocketSever;
import cn.wolfcode.mq.MQConstant;
import cn.wolfcode.mq.OrderMQResult;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@RocketMQMessageListener(
        consumerGroup = MQConstant.ORDER_RESULT_CONSUMER_GROUP,
        topic = MQConstant.ORDER_RESULT_TOPIC
)
@Component
@Slf4j
public class OrderResultMQMessageListener implements RocketMQListener<OrderMQResult> {


    @Override
    public void onMessage(OrderMQResult result) {
        String json = JSON.toJSONString(result);
        log.info("接收到订单结果消息:{}", json);
        WebSocketSever.sendMessage(result.getToken(), json);
    }
}
